set more off
program drop _all
set scheme s1mono
capture log close


/*open log and set directory:  update to suit*/
log using "C:\Users\AALICHT\Dropbox\Greene and Licht\data\R&R\Replication Materials\Greene&LichtReplication.log", replace
cd "C:\Users\AALICHT\Dropbox\Greene and Licht\data\R&R\Replication Materials\"
		

*PURPOSE:	This file will run the principal models, calculate and graph marginal
*			effects, and perform simulations for substantive interpretation of the
*			interaction effects as reported in Greene and Licht (2018). 
*SET-UP:	Before running this file, ensure that the datasets listed below
*			are saved in the same directory on your machine and update the log
*			and cd commands above to reflect your directory path. Also, ensure
*			that you have installed the outreg2 plug-in. Use <findit outreg2>
*			if it is not currently installed.
*AUTHOR:	Amanda A. Licht, Binghamton University
*MACHINE:	Lenovo ThinkStation running Stata13MP
*DATE:		7/17/2018
*MODIFIED:	10/11/2018
*FILE:		Greene&LichtReplication.do
*LOG:		Greene&LichtReplication.txt
*DATA:		Greene&Licht2018.dta		-full analysis dataset
*			Greene&Licht2018sims.dta	-100 obs of vars at interesting values
*OUTPUT:	
*	Data:		for ODA = 1 2 5 7 8, simresults`ODA'.dta	- 100K predicted values  
*															for each sector	of aid
*				simresultsCIs.dta							- mean, sigma, and CIs
*															from all sims
*				InSampleMarginalEffects.dta					
*	Graphs:		In Sample Combined Short and Long Term Marginal Effects Econ.gph
*				In Sample Combined Short and Long Term Marginal Effects Internat.gph
*				Predicted Aid Allocations across Sectors from Simulated Elections, Pro-internat.gph
*				Predicted Aid Allocations across Sectors from Simulated Elections, Anti-internat.gph
*	Tables		Greene&Licht2018ECMs.txt



/*Open and xtset data:*/
use Greene&LichtReplication.dta, clear
des

		xtset donorccode year

/*Run model on ODA purpose 1 and save initial table:*/

replace lagged_dv = L1.ODA_purpose1			/*use appropriate ODA variable to make lagged dv*/
#delimit ;
	xtpcse D1.ODA_purpose1
		D1.c.internat_lr##D1.c.econ_lr
		L1.c.internat_lr##L1.c.econ_lr
		coldwar 
		L1.realgdp
		L1.leftp_pctseats 
		L1.chrp_pctseats 
		L1.cab_pctseats  
		L1.ENcabparties 
		D1.realgdp 
		D1.leftp_pctseats 
		D1.chrp_pctseats 
		D1.cab_pctseats   
		D1.ENcabparties
		presidential
		lagged_dv , p; 
		outreg2 using Greene&Licht2018ECMs.txt, replace dec(3) addstat(Root Mean Squared Error, e(rmse))
		title("ECM Regressions by Sector w/Rescaled Preference Variables") 
		ctitle("ODA Purpose 1");
#delimit cr	
	/*Preserve matrices*/
		mat def b1 = e(b)
		mat def V1 = e(V)
	
	
*Open loop over the DVs to run the models for each sector of aid, appending
*the results to the same table and preserving the estimation matrices for
*use in calculating marginal effects and predicted values:
	
set more off
foreach ODA in 	2 5 7 8	{

	/*Open up dataset*/
		use Greene&LichtReplication.dta, clear

		replace lagged_dv = L1.ODA_purpose`ODA'			/*replace lagged dv w/appropriate ODA type*/
		
	/*Run ECM model:*/
	#delimit ;
	xtpcse D1.ODA_purpose`ODA'
		D1.c.internat_lr##D1.c.econ_lr
		L1.c.internat_lr##L1.c.econ_lr
		coldwar 
		L1.realgdp
		L1.leftp_pctseats 
		L1.chrp_pctseats 
		L1.cab_pctseats  
		L1.ENcabparties 
		D1.realgdp 
		D1.leftp_pctseats 
		D1.chrp_pctseats 
		D1.cab_pctseats   
		D1.ENcabparties
		presidential
		lagged_dv , p; 
	
	/*write results to table*/
		outreg2 using Greene&Licht2018ECMs.txt, append dec(3) addstat(Root Mean Squared Error, e(rmse))
		title("ECM Regressions by Sector w/Rescaled Preference Variables") 
		ctitle("ODA Purpose `ODA'");
	#delimit cr
	
	/*Preserve matrices*/
		mat def b`ODA' = e(b)
		mat def V`ODA' = e(V)
		
			}	/*close loop*/
		

*********************************		
*********************************
*Next, let's look at the marginal
*effects in the observed sample
*********************************
*********************************

/*Loop over ODA sectors:*/
foreach ODA in 1 2 5 7 8	{

	/*Calculate ME of delta internat, get sd, and make CIs:*/
	gen MEinternatD`ODA' 	= b`ODA'[1,1] + D1.econ_lr*b`ODA'[1,3]
	gen sd_MEinternatD`ODA'	= sqrt(V`ODA'[1,1] + D1.econ_lr^2*V`ODA'[3,3] + 2*D1.econ_lr*V`ODA'[1,3])

	gen MEinternatD`ODA'_lo = MEinternatD`ODA' - 1.96*sd_MEinternatD`ODA'
	gen MEinternatD`ODA'_hi = MEinternatD`ODA' + 1.96*sd_MEinternatD`ODA'
	
	gen MEinternatD`ODA'_lo90 = MEinternatD`ODA' - 1.645*sd_MEinternatD`ODA'
	gen MEinternatD`ODA'_hi90 = MEinternatD`ODA' + 1.645*sd_MEinternatD`ODA' 

	/*Calculate ME of delta econ, get sd, and make CIs:*/
	gen MEeconD`ODA' 	= b`ODA'[1,2] + D1.internat_lr*b`ODA'[1,3]
	gen sd_MEeconD`ODA'	= sqrt(V`ODA'[2,2] + D1.internat_lr^2*V`ODA'[3,3] + 2*D1.internat_lr*V`ODA'[1,3])

	gen MEeconD`ODA'_lo = MEeconD`ODA' - 1.96*sd_MEeconD`ODA'
	gen MEeconD`ODA'_hi = MEeconD`ODA' + 1.96*sd_MEeconD`ODA'
	
	gen MEeconD`ODA'_lo90 = MEeconD`ODA' - 1.645*sd_MEeconD`ODA'
	gen MEeconD`ODA'_hi90 = MEeconD`ODA' + 1.645*sd_MEeconD`ODA' 
	
	
	/*Calculate ME of lag internat, get sd, and make CIs:*/
	gen MEinternatL`ODA' 	= b`ODA'[1,4] + L1.econ_lr*b`ODA'[1,6]
	gen sd_MEinternatL`ODA'	= sqrt(V`ODA'[4,4] + L1.econ_lr^2*V`ODA'[6,6] + 2*L1.econ_lr*V`ODA'[4,6])

	gen MEinternatL`ODA'_lo = MEinternatL`ODA' - 1.96*sd_MEinternatL`ODA'
	gen MEinternatL`ODA'_hi = MEinternatL`ODA' + 1.96*sd_MEinternatL`ODA'
	
	gen MEinternatL`ODA'_lo90 = MEinternatL`ODA' - 1.645*sd_MEinternatL`ODA'
	gen MEinternatL`ODA'_hi90 = MEinternatL`ODA' + 1.645*sd_MEinternatL`ODA' 
	
	/*Calculate ME of lag econ, get sd, and make CIs:*/
	gen MEeconL`ODA' 	= b`ODA'[1,5] + L1.internat_lr*b`ODA'[1,6]
	gen sd_MEeconL`ODA'	= sqrt(V`ODA'[5,5] + L1.internat_lr^2*V`ODA'[6,6] + 2*L1.internat_lr*V`ODA'[5,6])

	gen MEeconL`ODA'_lo = MEeconL`ODA' - 1.96*sd_MEeconL`ODA'
	gen MEeconL`ODA'_hi = MEeconL`ODA' + 1.96*sd_MEeconL`ODA'
	
	gen MEeconL`ODA'_lo90 = MEeconL`ODA' - 1.645*sd_MEeconL`ODA'
	gen MEeconL`ODA'_hi90 = MEeconL`ODA' + 1.645*sd_MEeconL`ODA' 
								}	/*close loop*/
								
/*Make the diffs and lags into static variables for graphing:*/
foreach var in econ_lr internat_lr	{
	gen D1`var' = D1.`var'
	gen L1`var' = L1.`var'
									}

******************************************************************************									
*Graph the Marginal Effects, looping over the short-and long-term effects:
******************************************************************************

/*First, the effects for anti-internationalistm:*/

foreach lev in D L	{	/*loop over change and level effects*/

/*I want the left-most graph to have a title for the left-Yaxis, so I do it separately:*/
#delimit ;
twoway 	(hist `lev'1econ_lr, yaxis(2) width(.075) col(gs14) percent )
		(lowess MEinternat`lev'1_lo `lev'1econ_lr, sort yaxis(1)
			lc(gs5) lw(thin))
		(lowess MEinternat`lev'1_hi `lev'1econ_lr, sort 
			lc(gs5) lw(thin))	
		(lowess MEinternat`lev'1 `lev'1econ_lr, sort 
			lc(black) lw(thin)
				yscale(alt) yscale(alt axis(2))
				ylab(,labsi(small)) ylab(none, axis(2)) 
				yline(0, axis(1) lc(gs10) lp(dash) lw(thin))
				ytitle("Marginal Effect",  margin(tiny) size(small) axis(1))
				ytitle("", axis(2))
				xtitle("")
				title("ODA 1", size(small))),
		graphregion(margin(tiny))
		legend(off)
		name(i`lev'1, replace);

/*I want the right most graph to have a title for the scatter, so I do it separately:*/
#delimit ;
twoway 	(hist `lev'1econ_lr, yaxis(2) width(.075) col(gs14) percent )
		(lowess MEinternat`lev'8_lo `lev'1econ_lr, sort yaxis(1)
			lc(gs5) lw(thin))
		(lowess MEinternat`lev'8_hi `lev'1econ_lr, sort 
			lc(gs5) lw(thin))	
		(lowess MEinternat`lev'8 `lev'1econ_lr, sort 
			lc(black) lw(thin)
				yscale(alt) yscale(alt axis(2))
				ylab(none) ylab(, labsi(small) axis(2)) 
				yline(0, axis(1) lc(gs10) lp(dash) lw(thin))
				ytitle("",  size(small) axis(1))
				ytitle("Percentage of Cases", orientation(rvertical) axis(2) margin(tiny) size(small))
				xtitle("")
				title("ODA 8", size(small))),
		graphregion(margin(tiny))
		legend(off)
		name(i`lev'8, replace);	
#delimit cr

/*Loop over the other aid types to make the middle panels of the overall graph:*/
foreach ODA in 2 5 7  	{
#delimit ;
twoway 	(hist `lev'1econ_lr, yaxis(2) width(.075) col(gs14) lw(vvthin) percent )
		(lowess MEinternat`lev'`ODA'_lo `lev'1econ_lr, sort yaxis(1)
			lc(gs5) lw(thin))
		(lowess MEinternat`lev'`ODA'_hi `lev'1econ_lr, sort 
			lc(gs5) lw(thin))	
		(lowess MEinternat`lev'`ODA' `lev'1econ_lr, sort 
			lc(black) lw(thin)
				yscale(alt) yscale(alt axis(2))
				ylab(none, axis(2)) ylab(none, axis(1)) 
				yline(0, axis(1) lc(gs10) lp(dash) lw(thin))
				ytitle("", axis(1))
				ytitle("", axis(2))
				xtitle("")
				title("ODA `ODA'", size(small))),
		graphregion(margin(tiny))
		legend(off)
		name(i`lev'`ODA', replace);
#delimit cr				
			}
			}
/*combine graphs:*/	
#delimit ;		
graph combine iD1 iD2 iD5 iD7 iD8, rows(1) ycommon
	b1title("{&Delta}Economic Ideology", size(medsmall))
	title("Short Term Effect", size(medsmall))
name(iD, replace)
saving("In Sample Marginal Effect of Internat D1.gph", replace);
#delimit ;
graph combine iL1 iL2 iL5 iL7 iL8, rows(1) ycommon
	b1title("Economic Ideology t-1", size(medsmall))
	title("Long Term Effect", size(medsmall))
name(iL, replace)
saving("In Sample Marginal Effect of Internat L1.gph", replace);
#delimit ;
graph combine iD iL, rows(2) 
	title("Marginal Effects of Anti-Internationalism across Aid Types", size(medium))
saving("In Sample Combined Short and Long Term Marginal Effects Internat.gph", replace)
name(iboth, replace);
#delimit cr


/*Repeat the process for the other side of the interaction, economic ideology:*/
foreach lev in D L	{
/*I want the left-most graph to have a title for the left-Yaxis, so I do it separately:*/
#delimit ;
twoway 	(hist `lev'1internat_lr, yaxis(2) width(.02) col(gs14) percent )
		(lowess MEecon`lev'1_lo `lev'1internat_lr, sort yaxis(1)
			lc(gs5) lw(thin))
		(lowess MEecon`lev'1_hi `lev'1internat_lr, sort 
			lc(gs5) lw(thin))	
		(lowess MEecon`lev'1 `lev'1internat_lr, sort 
			lc(black) lw(thin)
				yscale(alt) yscale(alt axis(2))
				ylab(,labsi(small)) ylab(none, axis(2)) 
				yline(0, axis(1) lc(gs10) lp(dash) lw(thin))
				ytitle("Marginal Effect",  margin(tiny) size(small) axis(1))
				ytitle("", axis(2))
				xtitle("")
				title("ODA 1", size(small))),
		graphregion(margin(tiny))
		legend(off)
		name(e`lev'1, replace);

/*I want the right most graph to have a title for the scatter, so I do it separately:*/
#delimit ;
twoway 	(hist `lev'1internat_lr, yaxis(2) width(.02) col(gs14) percent )
		(lowess MEecon`lev'8_lo `lev'1internat_lr, sort yaxis(1)
			lc(gs5) lw(thin))
		(lowess MEecon`lev'8_hi `lev'1internat_lr, sort 
			lc(gs5) lw(thin))	
		(lowess MEecon`lev'8 `lev'1internat_lr, sort 
			lc(black) lw(thin)
				yscale(alt) yscale(alt axis(2))
				ylab(none) ylab(, labsi(small) axis(2)) 
				yline(0, axis(1) lc(gs10) lp(dash) lw(thin))
				ytitle("",  size(small) axis(1))
				ytitle("Percentage of Cases", orientation(rvertical) axis(2) margin(tiny) size(small))
				xtitle("")
				title("ODA 8", size(small))),
		graphregion(margin(tiny))
		legend(off)
		name(e`lev'8, replace);
#delimit cr		
/*Loop over the other aid types to make middle panels:	*/	
foreach ODA in 2 5 7  	{
#delimit ;
twoway 	(hist `lev'1internat_lr, yaxis(2) width(.02) col(gs14) lw(vvthin) percent )
		(lowess MEecon`lev'`ODA'_lo `lev'1internat_lr, sort yaxis(1)
			lc(gs5) lw(thin))
		(lowess MEecon`lev'`ODA'_hi `lev'1internat_lr, sort 
			lc(gs5) lw(thin))	
		(lowess MEecon`lev'`ODA' `lev'1internat_lr, sort 
			lc(black) lw(thin)
				yscale(alt) yscale(alt axis(2))
				ylab(none, axis(2)) ylab(none, axis(1)) 
				yline(0, axis(1) lc(gs10) lp(dash) lw(thin))
				ytitle("", axis(1))
				ytitle("", axis(2))
				xtitle("")
				title("ODA `ODA'", size(small))),
		graphregion(margin(tiny))
		legend(off)
		name(e`lev'`ODA', replace);
#delimit cr				
			}
			}

/*Combine the graphs:*/
#delimit ;
graph combine eD1 eD2 eD5 eD7 eD8, rows(1) ycommon
	b1title("{&Delta}Anti-Internationalism", size(medsmall))
	title("Short Term Effect", size(medsmall))
name(eD, replace)
saving("In Sample Marginal Effect of Econ D1.gph", replace);

#delimit ;
graph combine eL1 eL2 eL5 eL7 eL8, rows(1) ycommon
	b1title("Anti-Internationalism t-1", size(medsmall))
	title("Long Term Effect", size(medsmall))
name(eL, replace)
saving("In Sample Marginal Effect of Econ L1.gph", replace);

#delimit ;
graph combine eD eL, rows(2) 
	title("Marginal Effects of Economic Ideology across Aid Types", size(medium))
saving("In Sample Combined Short and Long Term Marginal Effects Econ.gph", replace)
name(eboth, replace);
#delimit cr

*Save the in-sample marginal effects for easy access later:
keep ME* L1internat_lr D1internat_lr L1econ_lr D1econ_lr
save InSampleMarginalEffects.dta, replace

		
****************************************************************		
****************************************************************		
*Write a program to calculate the predicted outcome 
*across ODA types as we vary parties' preferences
****************************************************************
****************************************************************


program define impulse_response
	
	syntax, aid(real) edelta(string) idelta(string)
	
	use Greene&Licht2018sims.dta, clear
	
	
	drawnorm double b1-b20, means(b`aid') cov(V`aid')
	
	*Calculate an initial value, for a mean government:
	#delimit ;	
	gen y`aid'_0	=	b1*0 + 
						b2*0 + 
						b3*0 + 
						b4*internat_lr_l + 
						b5*econ_lr_l+ 
						b6*econ_lr_l*internat_lr_l + 
						b7*0 + 
						b8*realgdp_l +  
						b9*leftp_pctseats_l  + 
						b10*chrp_pctseats_l +  
						b11*cab_pctseats_l + 
						b12*ENcabparties_l + 
						b13*realgdp_d +
						b14*leftp_pctseats_d +
						b15*chrp_pctseats_d  + 
						b16*cab_pctseats_d  +  
						b17*ENcabparties_d + 
						b18*0 + 
						b19*lagged_dv`aid' + 
						b20;
	#delimit cr	
				
		*update lagged_dv value:		
		replace lagged_dv`aid' = lagged_dv`aid'+y`aid'_0		
		
	*Predict value D`aid' in year of a change in govt:	
	#delimit ;	
	gen y`aid'_1	=	b1*interdelta_`idelta' + 
						b2*econdelta_`edelta' + 
						b3*interdelta_`idelta'*econdelta_`edelta' + 
						b4*internat_lr_l + 
						b5*econ_lr_l+ 
						b6*econ_lr_l*internat_lr_l + 
						b7*0 + 
						b8*realgdp_l +  
						b9*leftp_pctseats_l  + 
						b10*chrp_pctseats_l +  
						b11*cab_pctseats_l + 
						b12*ENcabparties_l + 
						b13*realgdp_d +
						b14*leftp_pctseats_d +
						b15*chrp_pctseats_d  + 
						b16*cab_pctseats_d  +  
						b17*ENcabparties_d + 
						b18*0 + 
						b19*lagged_dv`aid' + 
						b20;
				#delimit cr	
				
	*open loop over 5 years:
	forvalues  i=2(1)5	{

	local j=`i'-1		/*make a local to ease updating of lagged dv*/
	
	*update lagged dv to reflect last round's change:
	replace lagged_dv`aid'= lagged_dv`aid' + y`aid'_`j'
	
		*Generate predicted change in year i:
		#delimit ;
		gen y`aid'_`i'= b1*0 + 	
						b2*0 + 
						b3*0*0 + 
						b4*(internat_lr_l + interdelta_`idelta') + 
						b5*(econ_lr_l + econdelta_`edelta')+ 
						b6*(internat_lr_l + interdelta_`idelta')*(econ_lr_l + econdelta_`edelta') + 
						b7*0 + 
						b8*realgdp_l +  
						b9*leftp_pctseats_l  + 
						b10*chrp_pctseats_l +  
						b11*cab_pctseats_l + 
						b12*ENcabparties_l + 
						b13*realgdp_d +
						b14*leftp_pctseats_d +
						b15*chrp_pctseats_d  + 
						b16*cab_pctseats_d  +  
						b17*ENcabparties_d + 
						b18*0 + 
						b19*lagged_dv`aid' + 
						b20;
			#delimit cr			
				} 	/*close loop around years*/
				
			gen econdelta 	= "`edelta'"
			gen interdelta 	= "`idelta'"
				
	keep econdelta interdelta y`aid'*	/*keep only the variables we need*/
	
	*Append to results dataset and save:
	append using simresults`aid'.dta
	save simresults`aid'.dta, replace

end	/*close program*/


 /*save empty dataset for results*/
foreach aid in 1 2 5 7 8	{ 
clear
	label data  "Aid Race Sims w/econ_lr and internat lags@ mean in t=1"
save simresults`aid'.dta, emptyok replace
							}
	
	
*Run simulations:
set more off

	*open loops around variables that will move:	
	foreach aid in 1 2 5 7 8		{
	foreach edelta in left right 	{	
	foreach idelta in pro anti		{	

		
		simulate, reps(100): impulse_response, aid(`aid') edelta(`edelta') idelta(`idelta') 
		
									}
									}
									}

/*Make a place to store means and confidence intervals around predicted values:*/
clear
set obs 2
gen econdelta = "left" in 1
replace econdelta = "right" in 2

expand 2

bysort econdelta: gen interdelta = "pro" if _n==1
bysort econdelta: replace interdelta = "anti" if _n==2

save simresultsCIs.dta, replace emptyok
									
/*Open up results, and collapse down to mean and standard deviation, as allows 
easy calculation of confidence intervals using Normality assumption:*/
set more off
foreach aid in 1 2 5 7 8 	{
	use simresults`aid'.dta, clear

		#delimit ;
		collapse (mean) y`aid'_1
						y`aid'_2
						y`aid'_3
						y`aid'_4
						y`aid'_5
				(sd)	sd`aid'_1	=	y`aid'_1
						sd`aid'_2	=	y`aid'_2
						sd`aid'_3	=	y`aid'_3
						sd`aid'_4	=	y`aid'_4
						sd`aid'_5	=	y`aid'_5
						, by(econdelta interdelta);
	#delimit cr
	merge 1:1 econdelta interdelta using simresultsCIs.dta, nogen

	save simresultsCIs.dta, replace 
								}

sum
tab econdelta interdelta

/*Reshape data to make it more manageable!
this will create a variable to hold the time period:*/
#delimit ;
	reshape long 	y8_ y7_ y5_ y2_ y1_
					sd8_ sd7_ sd5_ sd2_ sd1_
		, i(econdelta interdelta) j(time);
#delimit cr

/*Rename and label for clarity:	*/
	foreach var in y sd			{
	foreach num in 8 7 5 2 1 	{
	
		rename `var'`num'_ `var'`num'
								}
								}
							
		lab var y1 "NonSQ Aid"
		lab var y2 "Budget Aid"
		lab var y5 "Disaster Aid"
		lab var y7 "Trade Aid"
		lab var y8 "Infra Aid"
		
/*Now, calculate confidence intervals:*/
foreach ODA in 1 2 5 7 8		{
	gen y`ODA'_lo = y`ODA' - 1.96*sd`ODA'
	gen y`ODA'_hi = y`ODA' + 1.96*sd`ODA'
						}

sum						

save simresultsCIs.dta, replace 


***********************************************************************
*Graph commands, looped over aid type and pro/anti internationalism:
***********************************************************************

gen time_r = time+.2	/*jitter time over for readability*/

/*First, the Pro-internationalist shift*/
#delimit ;
twoway (scatter y1 time if time>0&time<=5&econdelta=="left"&interdelta=="pro", msym(O) mc(gs10) msi(medium))
		(scatter y1 time_r if time>0&time<=5&econdelta=="right"&interdelta=="pro", msym(X) mc(black) msi(medium))
		(rcap y1_lo y1_hi time if time>0&time<=5&econdelta=="left"&interdelta=="pro", lc(gs10) lw(thin))
		(rcap y1_lo y1_hi time_r if time>0&time<=5&econdelta=="right"&interdelta=="pro", lc(black) lw(thin)
				yline(0, lc(gs12) lp(dash) lw(vthin))
				ylab(-.6(.2).6)),
			title("ODA Purpose 1", size(medsmall))
			xtitle("") xlabel(1(1)5)
			ytitle("{&Delta}Aid Allocation", margin(tiny))
			graphregion(margin(tiny))
		legend(order(1 "Left" 2 "Right" ) title("{&Delta}Econ Preferences:", size(vsmall))
				symxsi(small) symysi(small) size(small) cols(1) ring(0) pos(4))
	name(proO1, replace);
	
foreach ODA in 2 5 7 8  {;
twoway (scatter y`ODA' time if time>0&time<=5&econdelta=="left"&interdelta=="pro", msym(O) mc(gs10) msi(medium))
		(scatter y`ODA' time_r if time>0&time<=5&econdelta=="right"&interdelta=="pro", msym(X) mc(black) msi(medium))
		(rcap y`ODA'_lo y`ODA'_hi time if time>0&time<=5&econdelta=="left"&interdelta=="pro", lc(gs10) lw(thin))
		(rcap y`ODA'_lo y`ODA'_hi time_r if time>0&time<=5&econdelta=="right"&interdelta=="pro", lc(black) lw(thin)
				yline(0, lc(gs12) lp(dash) lw(vthin))),
			title("ODA Purpose `ODA'", size(medsmall))
			xtitle("") xlabel(1(1)5)
			ytitle("") ylabel(none)
		legend(off)
		graphregion(margin(tiny))
		name(proO`ODA', replace); 		
							};
graph combine proO1 proO2 proO5 proO7 proO8, ycommon rows(1)
	title("Predicted Aid Allocations of Internationalist Parties across Sectors", size(medium))
	b1title("Years in Office", size(medsmall))
	name(combo, replace)
saving("Predicted Aid Allocations across Sectors from Simulated Elections, Pro-internat.gph", replace)	;


/*Now, the anti-internationalist shift*/
#delimit ;
twoway (scatter y1 time if time>0&time<=5&econdelta=="left"&interdelta=="anti", msym(O) mc(gs10) msi(medium))
		(scatter y1 time_r if time>0&time<=5&econdelta=="right"&interdelta=="anti", msym(X) mc(black) msi(medium))
		(rcap y1_lo y1_hi time if time>0&time<=5&econdelta=="left"&interdelta=="anti", lc(gs10) lw(thin))
		(rcap y1_lo y1_hi time_r if time>0&time<=5&econdelta=="right"&interdelta=="anti", lc(black) lw(thin)
				yline(0, lc(gs12) lp(dash) lw(vthin))
				ylab(-.6(.2).6)),
			title("ODA Purpose 1", size(medsmall))
			xtitle("") xlabel(1(1)5)
			ytitle("{&Delta}Aid Allocation", margin(tiny))
			graphregion(margin(tiny))
		legend(order(1 "Left" 2 "Right" ) title("{&Delta}Econ Preferences:", size(vsmall))
				symxsi(small) symysi(small) size(small) cols(1) ring(0) pos(4))
	name(antiO1, replace);
	
foreach ODA in 2 5 7 8  {;
twoway (scatter y`ODA' time if time>0&time<=5&econdelta=="left"&interdelta=="anti", msym(O) mc(gs10) msi(medium))
		(scatter y`ODA' time_r if time>0&time<=5&econdelta=="right"&interdelta=="anti", msym(X) mc(black) msi(medium))
		(rcap y`ODA'_lo y`ODA'_hi time if time>0&time<=5&econdelta=="left"&interdelta=="anti", lc(gs10) lw(thin))
		(rcap y`ODA'_lo y`ODA'_hi time_r if time>0&time<=5&econdelta=="right"&interdelta=="anti", lc(black) lw(thin)
				yline(0, lc(gs12) lp(dash) lw(vthin))),
			title("ODA Purpose `ODA'", size(medsmall))
			xtitle("") xlabel(1(1)5)
			ytitle("") ylabel(none)
		legend(off)
		graphregion(margin(tiny))
		name(antiO`ODA', replace); 		
							};

graph combine antiO1 antiO2 antiO5 antiO7 antiO8, ycommon rows(1)
	title("Predicted Aid Allocations of Anti-Internationalist Parties across Sectors", size(medium))
	b1title("Years in Office", size(medsmall))
	name(acombo, replace)
saving("Predicted Aid Allocations across Sectors from Simulated Elections,AntiInternat.gph", replace)	;
#delimit cr 

log close	
